<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>一级分类</title>
      <link rel="stylesheet" type="text/css" href="../xhAdmin/css/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../xhAdmin/css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../xhAdmin/css/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../xhAdmin/css/demo/demo.css">
    <script type="text/javascript" src="../xhAdmin/js/jquery.min.js"></script>
    <script type="text/javascript" src="../xhAdmin/js/jquery.easyui.min.js"></script>
</head>

<body>
    <div id="toolbar-style">
        <a href="javascript:void(0)" id="styleAddBtn" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="styleAdd()">添加</a>
        <a href="javascript:void(0)" id="styleEditBtn" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="styleEdit()">修改</a>
        <a href="javascript:void(0)" id="styleDestroyBtn" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="styleDestroy()">删除</a>
    </div>
    <table id="style-table" class="easyui-datagrid" data-options="fit:true,border:false,url:'../xhStyle/all',method:'get'" style="width:auto;height:100%" toolbar="#toolbar-style" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true" pageSize="20">
        <thead>
            <tr>
                 <th field="sId" width="16%" align="center">一类编码</th>
                <th field="food_title_tId" width="16%" align="center">关联一类编码</th>
                <th field="img" width="16%" align="center" data-options="formatter:function(v){return '<img src='+v+' style=width:80px;height:80px;cursor:pointer;/>'}">图片内容</th>
                <th field="name" width="17%" align="center">二级分类名称</th>
                <th field="description" width="17%" align="center">说明</th>
                <th field="rule" width="17%" align="center">饮食原则</th>
                <th field="element" width="17%" align="center">明星营养素</th>
                <th field="main" width="17%" align="center">重点推荐五谷</th>
                <th field="other" width="17%" align="center">其他有效食材</th>
                <th field="prescription" width="17%" align="center">家庭祛病养生方</th>
                
                <th field="oldTime" width="17%" align="center">最开始更改时间</th>
                <th field="newTime" width="17%" align="center">最新更改时间</th>
            </tr>
        </thead>
    </table>
    <div id="dlg-styleAdd" class="easyui-dialog" style="width:650px;height:393px;padding:1px 1px" closed="true" buttons="#dlg-styleAdd-btn" align="center" data-options="modal:true">
        <form id="fm-styleAdd" method="post" novalidate enctype="multipart/form-data" >
            <table class="pattern" border="0" cellpadding="5" cellspacing="0">
              <tr>
				<th width="100px">所属一级分类：</th>
				<td colspan="3"><select class="easyui-combotree" name="food_title_tId" style="width:100%;" data-options="url:'../xhTitle/getJsonTreeData',method:'get',valueField:'id'" /></td>
                <th width="100px">二级分类名称：</th>
				<td colspan="3"><input type="text" id="name" name="name" class="easyui-textbox"  style="width:100%"/></td>
			</tr>
            <tr>
                <th>说明：</th>
				<td colspan="3"><input type="text" id="description" name="description" class="easyui-textbox"  style="width:100%"/></td>
                <th>饮食原则：</th>
               <td><input type="text" id="rule" name="rule" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>明星营养素：</th>
				<td colspan="3"><input type="text" id="element" name="element" class="easyui-textbox"  style="width:100%"/></td>
                <th>重点推荐五谷：</th>
               <td><input type="text" id="main" name="main" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>其他有效食材：</th>
				<td colspan="3"><input type="text" id="other" name="other" class="easyui-textbox"  style="width:100%"/></td>
                <th>家庭祛病养生方：</th>
               <td><input type="text" id="prescription" name="prescription" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>上传图片：</th>
				<td colspan="3"><input type="file" id="img" name="img" style="width:100%"/></td>
                <th>二类编码：</th>
				<td colspan="3"><input type="text" id="sId" name="sId" class="easyui-textbox"  style="width:100%"/></td>
            </tr>
            </table>
        </form>
    </div>
    <div id="dlg-styleAdd-btn">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="styleAddSave()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-styleAdd').dialog('close')" style="width:90px">关闭</a>
    </div>
    <div id="dlg-styleEdit" class="easyui-dialog" style="width:650px;height:393px;padding:1px 1px" closed="true" buttons="#dlg-styleEdit-btn" align="center" data-options="modal:true">
        <form id="fm-styleEdit" method="post" novalidate enctype="multipart/form-data">
            <table class="pattern" border="0">
			 <tr>
				<th width="100px">所属一级分类：</th>
				<td colspan="3"><select class="easyui-combotree" name="food_title_tId" style="width:100%;" data-options="url:'../xhTitle/getJsonTreeData',method:'get',valueField:'id'" /></td>
                <th width="100px">二级分类名称：</th>
				<td colspan="3"><input type="text" id="name" name="name" class="easyui-textbox"  style="width:100%"/></td>
			</tr>
            <tr>
                <th>说明：</th>
				<td colspan="3"><input type="text" id="description" name="description" class="easyui-textbox"  style="width:100%"/></td>
                <th>饮食原则：</th>
               <td><input type="text" id="rule" name="rule" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>明星营养素：</th>
				<td colspan="3"><input type="text" id="element" name="element" class="easyui-textbox"  style="width:100%"/></td>
                <th>重点推荐五谷：</th>
               <td><input type="text" id="main" name="main" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>其他有效食材：</th>
				<td colspan="3"><input type="text" id="other" name="other" class="easyui-textbox"  style="width:100%"/></td>
                <th>家庭祛病养生方：</th>
               <td><input type="text" id="prescription" name="prescription" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
			 <th>图片地址：</th>
			<td><input type="text" id="img" name="img" class="easyui-textbox" style="width:100%"></td>
			</tr>
            <tr>
                <th>上传图片：</th>
				<td colspan="3"><input type="file" id="img" name="img" style="width:100%"/></td>
                <th>二类编码：</th>
				<td colspan="3"><input type="text" id="sId" name="sId" class="easyui-textbox"  style="width:100%"/></td>
            </tr>
            <input type="hidden" name="id" />
            <input type="hidden" name="timestamp" />
			</table>
        </form>
    </div>
    <div id="dlg-styleEdit-btn">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="styleEditSave()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-styleEdit').dialog('close')" style="width:90px">关闭</a>
    </div>
    <div id="dlg-styleReadonly" class="easyui-dialog" style="width:650px;height:393px;padding:1px 1px" closed="true" buttons="#dlg-styleReadonly-btn" align="center" data-options="modal:true">
        <form id="fm-styleReadonly" method="post" novalidate>
            <table class="pattern" border="0" cellpadding="5" cellspacing="0">
			 <tr>
				<th width="100px">所属一级分类：</th>
				<td colspan="3"><select class="easyui-combotree" name="food_title_tId" style="width:100%;" data-options="url:'../xhTitle/getJsonTreeData',method:'get',valueField:'id'" /></td>
                <th width="100px">二级分类名称：</th>
				<td colspan="3"><input type="text" id="name" name="name" class="easyui-textbox"  style="width:100%"/></td>
			</tr>
            <tr>
                <th>说明：</th>
				<td colspan="3"><input type="text" id="description" name="description" class="easyui-textbox"  style="width:100%"/></td>
                <th>饮食原则：</th>
               <td><input type="text" id="rule" name="rule" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>明星营养素：</th>
				<td colspan="3"><input type="text" id="element" name="element" class="easyui-textbox"  style="width:100%"/></td>
                <th>重点推荐五谷：</th>
               <td><input type="text" id="main" name="main" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
                <th>其他有效食材：</th>
				<td colspan="3"><input type="text" id="other" name="other" class="easyui-textbox"  style="width:100%"/></td>
                <th>家庭祛病养生方：</th>
               <td><input type="text" id="prescription" name="prescription" class="easyui-textbox" style="width:100%"/></td>
            </tr>
            <tr>
			 <th>图片地址：</th>
			<td><input type="text" id="img" name="img" class="easyui-textbox" style="width:100%"></td>
			</tr>
            <tr>
                <th>上传图片：</th>
				<td colspan="3"><input type="file" id="img" name="img" style="width:100%"/></td>
                <th>二类编码：</th>
				<td colspan="3"><input type="text" id="sId" name="sId" class="easyui-textbox"  style="width:100%"/></td>
            </tr>
            <input type="hidden" name="id" />
            <input type="hidden" name="timestamp" />
			</table>
        </form>
    </div>
    <div id="dlg-styleReadonly-btn">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-styleReadonly').dialog('close')" style="width:90px">关闭</a>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        /*$.post('/jg/checkScope', {
            sessionName: 'f9'
        }, function(data) {
            if (data == false) {
                $('#toolbar-style #styleAddBtn').hide();
                $('#toolbar-style #styleEditBtn').hide();
                $('#toolbar-style #styleDestroyBtn').hide();
            }
        }, 'json');*/

        $("#style-table").datagrid({
            //双击事件  
            onDblClickRow: function(index, row) {
                if (row) {
                    $('#dlg-styleReadonly').dialog('open').dialog('center').dialog('setTitle', '查看一级分类信息');
                    $('#fm-styleReadonly').form('load', row);
                }
            }
        });

    });

    function styleAdd() {
        $('#dlg-styleAdd').dialog('open').dialog('center').dialog('setTitle', '添加一级分类信息');
        $('#fm-styleAdd').form('clear');
    }

    function styleAddSave() {
        $('#fm-styleAdd').form('submit', {
            url: '../xhStyle/add',
            onSubmit: function() {
                //进行表单验证
                //如果返回false阻止提交
                return $(this).form('enableValidation').form('validate');
            },
            success: function(data) {
                var data = eval('(' + data + ')'); // change the JSON string to javascript object
                if (data.result == 'success') {
                    $('#dlg-styleAdd').dialog('close');
                    $('#style-table').datagrid('reload');
                    $.messager.show({ // show error message
                        title: '操作完成',
                        msg: data.description
                    });
                } else {
                    $.messager.show({ // show error message
                        title: '出错了',
                        msg: data.description
                    });
                }
            }
        });

    }

    function styleEdit() {
        var row = $('#style-table').datagrid('getSelected');
        console.log(row);
        if (row) {
            $('#dlg-styleEdit').dialog('open').dialog('center').dialog('setTitle', '修改二级分类信息');
            $('#fm-styleEdit').form('load', row);
        }
    }

    function styleEditSave() {
        $('#fm-styleEdit').form('submit', {
            url: '../xhStyle/update',
            onSubmit: function() {
                //进行表单验证
                //如果返回false阻止提交
                return $(this).form('enableValidation').form('validate');
            },
            success: function(data) {
                var data = eval('(' + data + ')'); // change the JSON string to javascript object
                if (data.result == 'success') {
                    $('#dlg-styleEdit').dialog('close');
                    $('#style-table').datagrid('reload');
                    $.messager.show({ // show error message
                        title: '操作完成',
                        msg: data.description
                    });
                } else {
                    $.messager.show({ // show error message
                        title: '出错了',
                        msg: data.description
                    });
                }
            }
        });
    }

    function styleDestroy() {
        var row = $('#style-table').datagrid('getSelected');
        if (row) {
            $.messager.confirm('删除', '是否彻底删除该二级分类信息？？？', function(r) {
                if (r) {
                    $.post('../xhStyle/delete', {
                        id: row.id
                    }, function(data) {
                        if (data.result == 'success') {
                            $('#style-table').datagrid('reload'); // reload the user data
                            $.messager.show({ // show error message
                                title: '操作完成',
                                msg: data.description
                            });
                        } else {
                            $.messager.show({ // show error message
                                title: '出错了',
                                msg: data.description
                            });
                        }
                    }, 'json');
                }
            });
        }
    }
    </script>
</body>

</html>
